package com.etc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.etc.dao.RecruitmentMapper;
import com.etc.entity.ComResume;
import com.etc.entity.Company;
import com.etc.entity.Job;
import com.etc.entity.Jonseeker;
import com.etc.entity.LayUiData;
import com.etc.entity.Recruitment;
import com.etc.entity.User;
import com.etc.service.ComResumeService;
import com.etc.service.CompanyService;
import com.etc.service.JobService;
import com.etc.service.JonseeService;
import com.etc.service.RecruitmentService;
import com.etc.service.UserService;

@Controller
public class BackController {
	//实例化对象
	@Autowired
	private UserService us;
	@Autowired
	private JonseeService js;
	@Autowired
	private CompanyService cs;
	@Autowired
	private RecruitmentMapper recruitmentMapper;
	@Autowired
	private JobService jos;
	@Autowired
	private ComResumeService crs;
	@Autowired
	private RecruitmentService recs;
	
	/**
	 * 首页展示
	 * @return
	 */
	@GetMapping("shouYe1")
	public String shouYe()
	{
		return "frame";
	}
	
	/**
	 * 首页展示(内嵌)
	 * @return
	 */
	@GetMapping("shouYe2")
	public String shouYe1()
	{
		return "shouYe";
	}
	
	
	/**
	 * 待入驻企业分页模糊查询
	 * @return
	 */
	@GetMapping("comp_wait_list")
	@ResponseBody
	public LayUiData<Company> compB(@RequestParam(defaultValue="1", value="page") int page,@RequestParam(defaultValue="10" , value="limit") int limit,@RequestParam(defaultValue="", value="strLike") String strLike)
	{
		System.out.println(111);
		System.out.println(page);
		LayUiData<Company> layuiData = cs.getNoCompany(page, limit, strLike);
		layuiData.getData().forEach(System.out::println);
		return layuiData;
	}
	
	@GetMapping("compB")
	public String compB()
	{
		
		return "comp_wait_list";
	}
	//删除待入驻
	@PostMapping("delcompwait")
	@ResponseBody
	public String delcompwait(int comId)
	{
		System.out.println(comId);
		boolean flag = cs.delCompany(comId);
		return flag+"";
	}
	//修改待入驻
	@GetMapping("updcompwait")
	public String updcompwait(Company company)
	{
		System.out.println(company);
		boolean flag = cs.updateCompany(company);
		return "comp_wait_list";
	}
	
	/**
	 * 已入驻企业分页模糊查询
	 * @return
	 */
	@GetMapping("comp_list")
	@ResponseBody
	public LayUiData<Company> compA(@RequestParam(defaultValue="1", value="page") int page,@RequestParam(defaultValue="10" , value="limit") int limit,@RequestParam(defaultValue="", value="strLike") String strLike)
	{
		System.out.println(strLike);
		LayUiData<Company> layuiData = cs.getCompany(page, limit, strLike);
		return layuiData;
	}
	
	@GetMapping("compA")
	public String compA()
	{
		return "comp_list";
	}
	//删除已入驻
	@PostMapping("delcomp")
	@ResponseBody
	public String delcomp(int comId)
	{
		System.out.println(comId);
		boolean flag = cs.delCompany(comId);
		return flag+"";
	}
	//修改已入驻
	@GetMapping("updcomp")
	public String updcomp(Company company)
	{
		System.out.println(company);
		boolean flag = cs.updateCompany(company);
		return "comp_list";
	}
	
	/**
	 * 推荐企业分页模糊查询
	 * @return
	 */
	@GetMapping("rtc_list")
	@ResponseBody
	public LayUiData<Company> rtcA(@RequestParam(defaultValue="1", value="page") int page,@RequestParam(defaultValue="10" , value="limit") int limit,@RequestParam(defaultValue="", value="strLike") String strLike)
	{
		System.out.println(strLike);
		LayUiData<Company> layuiData = cs.getRecommend(page, limit, strLike);
		return layuiData;
	}
	
	@GetMapping("rtcA")
	public String rtcA()
	{
		return "rtc_list";
	}
	//修改推荐
	@GetMapping("updrtc")
	public String updrtc(Company company)
	{
		System.out.println(company);
		boolean flag = cs.updateCompany(company);
		System.out.println(flag);
		return "rtc_list";
	}
	
	
	
	
	/**
	 * 岗位管理列表
	 * @return
	 */
	@GetMapping("jop_list")
	@ResponseBody
	public LayUiData<Job> jopA(@RequestParam(defaultValue="1", value="page") int page,@RequestParam(defaultValue="10" , value="limit") int limit,@RequestParam(defaultValue="", value="strLike") String strLike)
	{
		System.out.println(strLike);
		LayUiData<Job> layuiData = jos.getJobByLike(page, limit, strLike);
		return layuiData;
	}
	
	@GetMapping("jopA")
	public String jopA()
	{
		return "jop_list";
	}
	//删除岗位
	@PostMapping("delJob")
	@ResponseBody
	public String delJob(int jobId)
	{
		System.out.println(jobId);
		int a = jos.delJob(jobId);
		
		if(a>0)
		{
			return "true";
		}else
		{
			return "false";
		}
	}
	
	/**
	 * 用户管理
	 * @return
	 */
	@GetMapping("user_list")
	@ResponseBody
	public LayUiData<User> userA(@RequestParam(defaultValue="1", value="page") int page,@RequestParam(defaultValue="10" , value="limit") int limit,@RequestParam(defaultValue="", value="strLike") String strLike)
	{
		System.out.println(strLike);
		LayUiData<User> layuiData = us.getUserByLike(page, limit, strLike);
		return layuiData;
	}
	
	@GetMapping("userA")
	public String userA()
	{
		return "user_list";
	}
	
	//删除用户
	@PostMapping("deluser")
	@ResponseBody
	public String deluser(int userId)
	{
		System.out.println(userId);
		boolean flag = us.delUser(userId);
		return flag+"";
	}
	//修改用户
	@GetMapping("upduser")
	public String upduser(User user)
	{
		System.out.println(user);
		boolean flag = us.update(user);
		System.out.println(flag);
		return "user_list";
	}
	
	
	/**
	 * 求职者管理
	 * @return
	 */
	@GetMapping("jonseeker_list")
	@ResponseBody
	public LayUiData<Jonseeker> jonseekerA(@RequestParam(defaultValue="1", value="page") int page,@RequestParam(defaultValue="10" , value="limit") int limit,@RequestParam(defaultValue="", value="strLike") String strLike)
	{
		System.out.println(page);
		System.out.println(strLike);
		LayUiData<Jonseeker> layuiData = js.getPage(page, limit, strLike);
		System.out.println(layuiData.getData());
		return layuiData;
	}
	
	@GetMapping("jonseekerA")
	public String jonseekerA()
	{
		return "jonseeker_list";
	}
	//删除求职者
	@PostMapping("deljonseeker")
	@ResponseBody
	public String deljonseeker(int userId)
	{
		System.out.println(userId);
		int a = js.deljon(userId);
		if(a>0)
		{
			return "true";
		}else
		{
			return "false";
		}
		
	}
	
	/**
	 * 简历管理
	 * @return
	 */
	@GetMapping("resume_list")
	@ResponseBody
	public LayUiData<ComResume> resumeA(@RequestParam(defaultValue="1", value="page") int page,@RequestParam(defaultValue="10" , value="limit") int limit,@RequestParam(defaultValue="", value="strLike") String strLike)
	{
		LayUiData<ComResume> layuiData = crs.queryIscomName(page, limit, strLike);
		return layuiData;
	}
	
	@GetMapping("resumeA")
	public String resumeA()
	{
		return "resume_list";
	}
	
	/**
	 * 招聘会管理
	 * @return
	 */
	@GetMapping("rec_list")
	@ResponseBody
	public LayUiData<Recruitment> recA(@RequestParam(defaultValue="1", value="page") int page,@RequestParam(defaultValue="10" , value="limit") int limit,@RequestParam(defaultValue="", value="strLike") String strLike)
	{
		LayUiData<Recruitment> layuiData = recs.getRecByLike(page, limit, strLike);
		return layuiData;
	}
	
	@GetMapping("recA")
	public String recA()
	{
		return "rec_list";
	}
	//删除招聘会
	@PostMapping("delrec")
	@ResponseBody
	public String delrec(String recName)
	{
		System.out.println(recName);
		boolean flag = recs.selectRecDel(recName);
		return flag+"";
	}
	//修改招聘会
	@GetMapping("updrec")
	public String updrec(Recruitment recruitment)
	{
		System.out.println(recruitment);
		boolean flag = recs.updRec(recruitment);
		System.out.println(flag);
		return "rec_list";
	}
		
	/**
	 * 发布招聘会
	 * @return
	 */
	@GetMapping("recB")
	public String recB()
	{
		return "rec_add";
	}
	
	@GetMapping("add")
	public String recB(Recruitment recruitment)
	{
		recruitmentMapper.AddRec(recruitment);
		
		return "rec_add";
	}
	
	
	/**
	 * 报名企业管理
	 * @return
	 */
	@GetMapping("recC")
	public String recC()
	{
		return "recjoin_list";
	}
	
}
